%% copy riak-0.14.2 source to learn dynamo implementation and erlang
%% author: lichuang
%% copy source from riak_kv_backend.erl

%% edynamo_kv_backend: backend behaviour 

-module(edynamo_kv_backend).
-export([behaviour_info/1]).
-export([callback_after/3]).

-spec behaviour_info(atom()) -> 'undefined' | [{atom(), arity()}].
behaviour_info(callbacks) ->
    [{start,2},       % (Partition, Config)
     {stop,1},        % (State) 
     {get,2},         % (State, BKey)
     {put,3},         % (State, BKey, Val)
     {list,1},        % (State)
     {list_bucket,2}, % (State, Bucket)
     {delete,2},      % (State, BKey)
     {drop,1},        % (State)
     {fold,3},        % (State, Folder, Acc), Folder({B,K},V,Acc)
     {is_empty,1},    % (State)
     {callback,3}];   % (State, Ref, Msg) ->
behaviour_info(_Other) ->
    undefined.

%% Queue a callback for the backend after Time ms.
-spec callback_after(integer(), reference(), term()) -> reference().
callback_after(Time, Ref, Msg) when is_integer(Time), is_reference(Ref) ->
  edynamo_vnode:send_command_after(Time, {backend_callback, Ref, Msg}).
